export default class orc_utils {
    /**
    * 随机一个整数数字[min,max]
    * @param min 从min开始
    * @param max 到max结束
    * @returns {*}
    */
   public static get_random(min:number, max:number):number 
   {
       if (isNaN(min) || isNaN(max))return 0;
       if (min >= max) return min;
       var temp = (Math.random() * (max - min + 1) ) + min ;
       temp = Math.floor(temp);
       if(temp == max +1)
       {
           return max;
       }
       else
       {
           return temp;
       }
   }

   /**
    * 讲数字number转化成string,20300 = 2.03万
    * @param number 数字
   */
    public static string_number(number:number):string
    {
        var number_string = '';
        if(number >= 10000)
        {
            number_string = String((number/10000).toFixed(2))+'万';
        }
        else
        {
            number_string = String(number);
        }
        return number_string;
    }

   /**
    * 将秒时间转换为 03:15这种格式
    * @param time 
    */
    public static clock_convert(time:number):Array<string>
    {        
        let minus:String = ('00' + String(Math.floor(Number(time) / 60))).slice(-2);
        let second:String = ('00' + String(Number(time) % 60)).slice(-2);
        let clock_string = [];
        clock_string[0] = minus;
        clock_string[1] = second;
        return clock_string;        
    }

   /**
    * 将json数据转化成formdata
    * @param json 
   */
    public static json_to_formdata(json:any)
    {
        let form = new FormData();   
        for(let key in json)
        {
            form.append(key,json[key])
        }
        return form;
    }

    /**
     * 将数据拼接起来
     * @param obj 
     */
    public static json_to_substr(obj) {
        if (obj) {
            var params = "";
            for (var key in obj) {
                if (obj.hasOwnProperty(key)) {
                    params += key + "=" + obj[key] + "&";
                }
            }
            return params.substr(0, params.length - 1);
        }
        else {
            return "";
        }
    }
}
